package org.yiqixue.accounts.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.yiqixue.accounts.dto.TransactionDTO;
import org.yiqixue.accounts.entity.TransactionType;
import org.yiqixue.accounts.service.TransactionService;

import java.util.List;

/**
 * 交易控制器
 * 处理所有与交易相关的HTTP请求
 */
@RestController
@RequestMapping("/api/transactions")
@RequiredArgsConstructor
@Tag(name = "交易管理", description = "处理交易相关的所有操作")
public class TransactionController {

    private final TransactionService transactionService;

    /**
     * 创建新交易
     * @param transactionDTO 交易信息
     * @return 创建的交易信息
     */
    @PostMapping
    @Operation(summary = "创建新交易", description = "创建一个新的交易记录，如存款、取款等")
    public ResponseEntity<TransactionDTO> createTransaction(@RequestBody TransactionDTO transactionDTO) {
        return ResponseEntity.ok(transactionService.createTransaction(transactionDTO));
    }

    /**
     * 查询指定手机号的当日特定类型交易
     * @param phoneNumber 手机号
     * @param type 交易类型
     * @return 交易列表
     */
    @GetMapping("/today")
    @Operation(summary = "查询当日交易", description = "根据手机号和交易类型查询当日的所有交易记录")
    public ResponseEntity<List<TransactionDTO>> getTodayTransactions(
            @RequestParam String phoneNumber,
            @RequestParam TransactionType type) {
        return ResponseEntity.ok(transactionService.findTodayTransactions(phoneNumber, type));
    }
} 